package utils

import (
	"tt_erp/model"

	"golang.org/x/crypto/bcrypt"
	"gorm.io/gorm"
)

// 判断手机号是否存在
func IsTelephoneExist(db *gorm.DB, telephone string) bool {
	var user model.User
	db.Where("telephone=?", telephone).First(&user)
	return user.ID != 0
}

// 判断用户是否存在
func IsUserExist(db *gorm.DB, username string) bool {
	var user model.User
	db.Where("username=?", username).First(&user)
	return user.ID != 0
}

// 判断密码是否正确
func CryptographicCheck(user model.User, password string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password))
	return err == nil
}
